package com.hongdee.base.imp.dao.impl;

import com.hongdee.base.basedao.impl.BaseDaoImpl;
import com.hongdee.base.imp.dao.IExcelSchemePropertyDao;
import com.hongdee.base.imp.entity.TExcelSchemeProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 名  称:ExcelSchemePropertyDaoImpl
 * 类  型: class
 * 描  述: 用一句话描述类的作用
 * 路  径:com.hongdee.base.imp.dao.impl
 * 作  者:My
 * 日  期:2017/2/15 11:47
 */
@Service
public class ExcelSchemePropertyDaoImpl extends BaseDaoImpl implements IExcelSchemePropertyDao {
    @Override
    public List<TExcelSchemeProperty> getProperyListBySchemeId(String schemeId) {
        if (StringUtils.isEmpty(schemeId))
            return null;

        try {
            List<Map> mapList = this.getJdbcDao().queryForMapListBySql("select * from "
                    + TExcelSchemeProperty.TABLE + " where scheme_id='" + schemeId + "'");
            if ( null == mapList )
                return null;

            List<TExcelSchemeProperty> propList = new ArrayList<TExcelSchemeProperty>();
            for (int i = 0; i < mapList.size(); i++ )
            {
                propList.add( new TExcelSchemeProperty(mapList.get(i)));
            }
            return propList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public boolean deleteObject(TExcelSchemeProperty esp) {
        try {
            this.getHibernateDao().delEntity(TExcelSchemeProperty.class, "id", esp.getId());
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
